package com.baseframe.tool.utils.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.Nullable;

public class SpringUtil implements ApplicationContextAware {

    private static ApplicationContext context;
    @Override
    public void setApplicationContext(@Nullable ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }

    public static <T> T getBean(Class<T> clazz){
        return context.getBean(clazz);
    }

    public static Object getBean(String beanName){

        return context.getBean(beanName);
    }

    public static <T> T getBean(String beanName,Class<T> beanType){
        return context.getBean(beanName,beanType);
    }


}
